package com.bto.solar.work.controller;

import com.alibaba.fastjson2.JSONArray;
import com.bto.solar.work.common.R;
import com.bto.solar.work.entity.Department;
import com.bto.solar.work.entity.User;
import com.bto.solar.work.service.BtoDepartmentService;
import com.bto.solar.work.vo.UserVO;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author adrian
 * @since 2023-08-09
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private BtoDepartmentService btoDepartmentService;

    /**
     * 通过 公司ID 获取部门列表
     */
    @GetMapping("/companyId")
    public R<List<UserVO.Department>> getDepartmentByCompanyId(@RequestParam(value = "companyId") Long companyId) {
        return R.ok(btoDepartmentService.getDepartmentListByCompanyId(companyId));
    }

    /**
     *部门——所有的部门信息
     * */
    @GetMapping("/get")
    public R<JSONArray> getDepartmentList(){
        JSONArray allOrg = btoDepartmentService.getAllOrg();
        return R.ok(allOrg,"请求成功！" );
    }

    /**
     * 部门——新增
     * */
    @PostMapping("/add")
    public R<String> addDepartment(@RequestBody(required = true) @ApiParam("添加部门") Department department){
        return btoDepartmentService.addDepartment(department);
    }

    /**
     * 部门——修改
     * */
    @PutMapping("/update/{id}")
    public R<String> updateDepartment(@RequestBody(required = true) @ApiParam("修改部门") Department department ,
                                      @PathVariable("id")  Integer id){
        return btoDepartmentService.updateDepartment(department , id);
    }

    /**
     * 部门——删除
     * */
    @DeleteMapping("/delete/{id}")
    public R<String> deleteDepartment(@PathVariable("id")  Integer id){
        return btoDepartmentService.deleteDepartment(id);
    }

    /**
     * 获取用户表
     * 部门负责人的id选项
     * */
    @GetMapping("/getUserId")
    public R<List<User>> getUserId(){
        List<User> userList = btoDepartmentService.getUserList();
        return R.ok(userList , "用户请求成功");
    }


}
